package com.eclipse.org.snms.serializer.stickyNoteList;

import com.eclipse.org.snms.*;

import java.util.ArrayList;
/**
 * 
 * @author jinzi
 *
 */
/*
 * This is a singleton class
 * There will be one and only one sticky notes list exists in the overall system
 */
public class StickyNoteList {
	private static StickyNoteList uniqueInstance;
	private static ArrayList<StickyNote> stickyNoteList;
	//private constructor 
	private StickyNoteList(){}
	//get the unique Instance of this class
	public static synchronized StickyNoteList getUniqueInstance(){
		if(uniqueInstance == null){
			uniqueInstance = new StickyNoteList();
			stickyNoteList = new ArrayList<StickyNote>();
		}
		return uniqueInstance;
	}
	
	public void addStickyNote(StickyNote stickyNote){
		stickyNoteList.add(stickyNote);
	}
	
	public void deleteStickyNote(StickyNote stickyNote){
		stickyNoteList.remove(stickyNote);
	}
	
	public void updateStickyNote(StickyNote stickyNote){
		int id = stickyNote.getId();
		for(int i = 0; i < stickyNoteList.size(); i++){
			if(stickyNoteList.get(i).getId() == id){
				stickyNoteList.remove(i);
				stickyNoteList.add(i, stickyNote);
				break;
			}
		}
	}
	
	public ArrayList<StickyNote> getStickyNote(){
		return stickyNoteList;		
	}
}
